{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# LAMMPS Tutorials 01. Running your first LAMMPS simulation!\n",
    "\n",
    "### Author: Mark Tschopp, mark.a.tschopp.civ at mail.mil\n",
    "\n",
    "Please contact me if you have a problem with this tutorial, so I can modify in Github.  I have added FAQs, and will update my versions of LAMMPS in the future to keep the scripts current.\n",
    "\n",
    "The latest version of this [Jupyter Notebook](http://ipython.org/notebook.html) tutorial is available at https://github.com/mrkllntschpp/lammps-tutorials.\n",
    "\n",
    "The original tutorials are given here: https://icme.hpc.msstate.edu/mediawiki/index.php/LAMMPS_tutorials.  A number of these tutorials are out of date and have been ported over into the current iPython Jupyter Notebook tutorials on github.\n",
    "\n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Description:\n",
    "<a id=\"Sec1\"></a>\n",
    "This is a quick tutorial to running a LAMMPS simulation on a Windows machine. For this simple example, the molecular simulation calculates the equilibrium lattice constant and corresponding cohesive energy for aluminum in the face-centered cubic (fcc) lattice structure (see below).\n",
    "\n",
    "<img src=\"https://icme.hpc.msstate.edu/mediawiki/images/e/ef/Fcc_stereo.gif\" alt=\"Face-centered Cubic Lattice Structure\" title=\"FCC Lattice Structure\" />"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "## Step 1: Download LAMMPS for Windows Executable\n",
    "<a id=\"Step1\"></a>\n",
    "\n",
    "Follow these steps to download the LAMMPS Windows Executable: \n",
    "1. Goto the LAMMPS download webpage, https://lammps.sandia.gov/download.html\n",
    "1. Click on Pre-built LAMMPS Windows executables \n",
    "1. Click the \"download now\" button. \n",
    "\n",
    "If you wish to run LAMMPS in a Unix shell, you must download a version on the download webpage and compile an executable. \n",
    "\n",
    "Voila! Easy as that. \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "## Step 2: Download an Interatomic Potential\n",
    "<a id=\"Step2\"></a>\n",
    "\n",
    "Follow these steps to download an interatomic potential. \n",
    "1. Go to the NIST Interatomic Potential webpage, https://www.ctcms.nist.gov/potentials/\n",
    "1. Click on Al for an aluminum single element potential \n",
    "1. Click on whichever potential you like. For this example, use the Mishin *et al.* potential, Al99.eam.alloy \n",
    "1. Save this in the same directory as the LAMMPS executable. \n",
    "\n",
    "Go ahead and open up the file in Wordpad, if you want to see what an interatomic potential for Al in the embedded atom method (EAM) alloy format looks like.  There is usually header information pertaining to the author of the potential and the first peer-reviewed paper describing its use.\n",
    "\n",
    "<br>\n",
    "<div class=\"alert alert-danger\">\n",
    "<strong>Danger, Will Robinson!</strong> <br><br>\n",
    "Potential Mistake 1. If you are not careful when you download, Windows may add a .txt or .html to the end of the file.  Then when the LAMMPS input script tries to call the file, there is an error because it can't find it. <br><br>\n",
    "Potential Mistake 2. If it is not saved in the same directory where LAMMPS is run out of, LAMMPS will not know where to find it.  May need to insert PATH of LAMMPS executable.\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "## Step 3: Download an Input File\n",
    "<a id=\"Step3\"></a>\n",
    "\n",
    "This input script was run using the Aug 2015 version of LAMMPS. Changes in some commands may require revision of the input script. To get the input file, you have a few options:\n",
    "\n",
    "*  Copy the text below and paste it into a text file, `calc_fcc.in`. Use the `Paste Special` command with unformatted text into the file. \n",
    "*  Or, I added the command `%%writefile calc_fcc.in` to the Jupyter Notebook which should just do everything for you!\n",
    "\n",
    "Obviously, if the second option worked, you are all set!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Overwriting calc_fcc.in\n"
     ]
    }
   ],
   "source": [
    "%%writefile calc_fcc.in\n",
    "######################################\n",
    "# LAMMPS INPUT SCRIPT\n",
    "# Find minimum energy fcc (face-centered cubic) atomic configuration\n",
    "# Mark Tschopp\n",
    "# Syntax, lmp_exe < calc_fcc.in\n",
    "\n",
    "######################################\n",
    "# INITIALIZATION\n",
    "clear \n",
    "units metal \n",
    "dimension 3 \n",
    "boundary p p p \n",
    "atom_style atomic \n",
    "atom_modify map array\n",
    "\n",
    "######################################\n",
    "# ATOM DEFINITION\n",
    "lattice fcc 4 orient x 1 1 0 orient y -1 1 0 orient z 0 0 1  \n",
    "region box block 0 1 0 1 0 1 units lattice\n",
    "create_box 1 box\n",
    "create_atoms 1 box\n",
    "replicate 1 1 1\n",
    "\n",
    "######################################\n",
    "# DEFINE INTERATOMIC POTENTIAL\n",
    "pair_style eam/alloy \n",
    "pair_coeff * * Al99.eam.alloy Al\n",
    "neighbor 2.0 bin \n",
    "neigh_modify delay 10 check yes \n",
    " \n",
    "######################################\n",
    "# DEFINE COMPUTES \n",
    "compute eng all pe/atom \n",
    "compute eatoms all reduce sum c_eng \n",
    "\n",
    "#####################################################\n",
    "# MINIMIZATION\n",
    "reset_timestep 0 \n",
    "fix 1 all box/relax iso 0.0 vmax 0.001\n",
    "thermo 10 \n",
    "thermo_style custom step pe lx ly lz press c_eatoms \n",
    "min_style cg \n",
    "minimize 1e-25 1e-25 5000 10000 \n",
    "\n",
    "variable natoms equal \"count(all)\" \n",
    "variable teng equal \"c_eatoms\"\n",
    "variable length equal \"lx\"\n",
    "variable ecoh equal \"v_teng/v_natoms\"\n",
    "\n",
    "print \"Total energy (eV) = ${teng};\"\n",
    "print \"Number of atoms = ${natoms};\"\n",
    "print \"Lattice constant (Angstoms) = ${length};\"\n",
    "print \"Cohesive energy (eV) = ${ecoh};\"\n",
    "\n",
    "print \"All done!\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Awesome!  That little script should have written the above text to the file `calc_fcc.in`.  To check, let's execute a command on the present directory listing all files that end in `*.in`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " Volume in drive C is OS\n",
      " Volume Serial Number is 58E7-437A\n",
      "\n",
      " Directory of C:\\Users\\markt\\Desktop\\lammps-tutorials\n",
      "\n",
      "04/17/2020  04:03 PM             1,447 calc_fcc.in\n",
      "04/17/2020  04:02 PM             1,564 calc_fcc_ver1.in\n",
      "04/17/2020  04:02 PM             1,233 calc_fcc_ver2.in\n",
      "               3 File(s)          4,244 bytes\n",
      "               0 Dir(s)  784,678,084,608 bytes free\n"
     ]
    }
   ],
   "source": [
    "!dir *.in"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If that didn't seem to work, we could open a (new) input file to write this script to it using Python (I removed all the comments):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "file = open(\"calc_fcc.in\", \"w\")\n",
    "file.write(\"clear\\n \")\n",
    "file.write(\"units metal \\n \")\n",
    "file.write(\"dimension 3 \\n \")\n",
    "file.write(\"boundary p p p \\n \")\n",
    "file.write(\"atom_style atomic \\n \")\n",
    "file.write(\"atom_modify map array \\n \") \n",
    "file.write(\"lattice fcc 4 \\n \")\n",
    "file.write(\"region box block 0 1 0 1 0 1 units lattice \\n \")\n",
    "file.write(\"create_box 1 box \\n \")\n",
    "file.write(\"lattice fcc 4 orient x 1 0 0 orient y 0 1 0 orient z 0 0 1\\n \")\n",
    "file.write(\"create_atoms 1 box \\n \")\n",
    "file.write(\"replicate 1 1 1\\n \")\n",
    "file.write(\"pair_style eam/alloy\\n \") \n",
    "file.write(\"pair_coeff * * Al99.eam.alloy Al\\n \")\n",
    "file.write(\"neighbor 2.0 bin \\n \")\n",
    "file.write(\"neigh_modify delay 10 check yes\\n \")\n",
    "file.write(\"compute eng all pe/atom \\n \")\n",
    "file.write(\"compute eatoms all reduce sum c_eng \\n \")\n",
    "file.write(\"reset_timestep 0 \\n \")\n",
    "file.write(\"fix 1 all box/relax iso 0.0 vmax 0.001\\n \")\n",
    "file.write(\"thermo 10 \\n \")\n",
    "file.write(\"thermo_style custom step pe lx ly lz press c_eatoms \\n \")\n",
    "file.write(\"min_style cg \\n \")\n",
    "file.write(\"minimize 1e-25 1e-25 5000 10000 \\n \")\n",
    "file.write(\"variable natoms equal \\\"count(all)\\\"\\n \") \n",
    "file.write(\"variable teng equal \\\"c_eatoms\\\"\\n \")\n",
    "file.write(\"variable length equal \\\"lx\\\"\\n \")\n",
    "file.write(\"variable ecoh equal \\\"v_teng/v_natoms\\\"\\n \")\n",
    "file.write(\"print \\\"Total energy (eV) = ${teng};\\\"\\n \")\n",
    "file.write(\"print \\\"Number of atoms = ${natoms};\\\"\\n \")\n",
    "file.write(\"print \\\"Lattice constant (Angstoms) = ${length};\\\"\\n \")\n",
    "file.write(\"print \\\"Cohesive energy (eV) = ${ecoh};\\\"\\n \")\n",
    "file.write(\"print \\\"All done!\\\"\\n \")\n",
    "file.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "## Step 4: Running LAMMPS in Windows\n",
    "\n",
    "### Run this using LAMMPS in Windows, Method 1 \n",
    "\n",
    "Follow these steps if running LAMMPS in Windows: \n",
    "1. Click on the Start button on the toolbar \n",
    "1. Click on Run... \n",
    "1. Enter `cmd` and hit OK \n",
    "1. In new window, change to the directory that contains the LAMMPS executable (lmp_win_no-mpi.exe), the input script (calc_fcc.in), and the potential file (Al99.eam.alloy). For example, if these are on the desktop, type 'cd h:/desktop' to change to the desktop (or wherever these are). \n",
    "1. Type `lmp_serial < calc_fcc.in` \n",
    "1. If the simulation completes, then it will type \"All done!\" Awesome!\n",
    "\n",
    "Wait, what? It didn't work? OK, quick check. Can you actually run the LAMMPS executable?  Find the executable and its path.  Most likely the executable is in a different directory than the input script and the potential file.  So, try this:\n",
    "\n",
    "In the command prompt window, can you type in the location of the LAMMPS executable?  If it's in the same directory that you are in, then it could be as easy as `lmp_serial`.  If not, you can run LAMMPS even when it lies in another directory somewhere, like in `C:/Program\\ Files/LAMMPS\\ 64-bit\\ 20Apr2018/bin/lmp_serial`.  If you click enter and nothing happens, then ... good!  Hit `CTL + C` to exit.  It should tell you the current version, i.e., \"LAMMPS (20 Apr 2018)\".  If it gives you an error, then the path to the executable isn't right, try again.  Remember that if you are using folders with spaces in them, then you need to enter `'\\' + ' '` within the path."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Run this using LAMMPS in Windows, Method 2 \n",
    "\n",
    "An alternative way to run this in Windows is to develop a _*.bat_ file, which is a Windows executable file. For instance, create a new text file and change the extension from *.txt* to *.bat*. By double clicking on a _*.bat_ file, you will execute the lines of scripts within the file. Now, don't double click to open, but rather right click and click on edit. Then enter the following lines: "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div>\n",
    "@echo off <br>\n",
    "lmp_serial.exe < calc_fcc.in <br>\n",
    "echo All done! <br>\n",
    "echo Press a key to end <br>\n",
    "pause > nul </div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "...which works if your administrator lets you run executables from your batch files on Windows 10. Try it by dropping it in the same folder as the LAMMPS executable, input script, and potential file and double clicking... voila!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Run this using LAMMPS in Jupyter Notebook, Method 3\n",
    "\n",
    "OK, this is cool!  We can actually run this from Jupyter Notebook.  Let's try it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "LAMMPS (24 Jan 2020)\n",
      "OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (../comm.cpp:94)\n",
      "  using 1 OpenMP thread(s) per MPI task\n",
      "OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (../comm.cpp:94)\n",
      "  using 1 OpenMP thread(s) per MPI task\n",
      "Lattice spacing in x,y,z = 4 4 4\n",
      "Created orthogonal box = (0 0 0) to (4 4 4)\n",
      "  1 by 1 by 1 MPI processor grid\n",
      "Lattice spacing in x,y,z = 4 4 4\n",
      "Created 4 atoms\n",
      "  create_atoms CPU = 0 secs\n",
      "Replicating atoms ...\n",
      "  orthogonal box = (0 0 0) to (4 4 4)\n",
      "  1 by 1 by 1 MPI processor grid\n",
      "  4 atoms\n",
      "  replicate CPU = 0 secs\n",
      "WARNING: Using 'neigh_modify every 1 delay 0 check yes' setting during minimization (../min.cpp:178)\n",
      "Neighbor list info ...\n",
      "  update every 1 steps, delay 0 steps, check yes\n",
      "  max neighbors/atom: 2000, page size: 100000\n",
      "  master list distance cutoff = 8.28721\n",
      "  ghost atom cutoff = 8.28721\n",
      "  binsize = 4.1436, bins = 1 1 1\n",
      "  1 neighbor lists, perpetual/occasional/extra = 1 0 0\n",
      "  (1) pair eam/alloy, perpetual\n",
      "      attributes: half, newton on\n",
      "      pair build: half/bin/atomonly/newton\n",
      "      stencil: half/bin/3d/newton\n",
      "      bin: standard\n",
      "Setting up cg style minimization ...\n",
      "  Unit style    : metal\n",
      "  Current step  : 0\n",
      "WARNING: Energy due to 1 extra global DOFs will be included in minimizer energies\n",
      "Per MPI rank memory allocation (min/avg/max) = 4.495 | 4.495 | 4.495 Mbytes\n",
      "Step PotEng Lx Ly Lz Press c_eatoms \n",
      "       0   -13.417787            4            4            4     29590.11   -13.417787 \n",
      "      10   -13.439104         4.04         4.04         4.04    5853.9553   -13.439104 \n",
      "      20       -13.44    4.0500047    4.0500047    4.0500047 2.1131131e-10       -13.44 \n",
      "      29       -13.44    4.0500047    4.0500047    4.0500047 4.7215918e-10       -13.44 \n",
      "Loop time of 0.00999594 on 1 procs for 29 steps with 4 atoms\n",
      "\n",
      "0.0% CPU use with 1 MPI tasks x 1 OpenMP threads\n",
      "\n",
      "Minimization stats:\n",
      "  Stopping criterion = energy tolerance\n",
      "  Energy initial, next-to-last, final = \n",
      "        -13.4177872966     -13.4399999527     -13.4399999527\n",
      "  Force two-norm initial, final = 3.54599 5.81382e-14\n",
      "  Force max component initial, final = 3.54599 5.80057e-14\n",
      "  Final line search alpha, max atom move = 1 5.80057e-14\n",
      "  Iterations, force evaluations = 29 46\n",
      "\n",
      "MPI task timing breakdown:\n",
      "Section |  min time  |  avg time  |  max time  |%varavg| %total\n",
      "---------------------------------------------------------------\n",
      "Pair    | 0          | 0          | 0          |   0.0 |  0.00\n",
      "Neigh   | 0          | 0          | 0          |   0.0 |  0.00\n",
      "Comm    | 0          | 0          | 0          |   0.0 |  0.00\n",
      "Output  | 0          | 0          | 0          |   0.0 |  0.00\n",
      "Modify  | 0          | 0          | 0          |   0.0 |  0.00\n",
      "Other   |            | 0.009996   |            |       |100.00\n",
      "\n",
      "Nlocal:    4 ave 4 max 4 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "Nghost:    662 ave 662 max 662 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "Neighs:    280 ave 280 max 280 min\n",
      "Histogram: 1 0 0 0 0 0 0 0 0 0\n",
      "\n",
      "Total # of neighbors = 280\n",
      "Ave neighs/atom = 70\n",
      "Neighbor list builds = 0\n",
      "Dangerous builds = 0\n",
      "Total energy (eV) = -13.4399999527352;\n",
      "Number of atoms = 4;\n",
      "Lattice constant (Angstoms) = 4.05000466178543;\n",
      "Cohesive energy (eV) = -3.3599999881838;\n",
      "All done!\n",
      "Total wall time: 0:00:00\n"
     ]
    }
   ],
   "source": [
    "!\"C:/Program Files/LAMMPS 64-bit 24Jan2020/bin/lmp_serial\" < calc_fcc.in"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Sweet!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Run this using LAMMPS in UNIX, Method 4\n",
    "\n",
    "If in a Unix environment, simply type `LAMMPS executable < input file`. If you wish to use multiple processors, use the mpirun command. For example, `mpirun -np 8 LAMMPS executable < input file` runs the simulation on 8 processors. \n",
    "\n",
    "The end of the logfile/screen output should look like this:\n",
    "\n",
    "<br>\n",
    "<div class=\"alert alert-block alert-info\">\n",
    "Total energy (eV) = -13.43999995; <br>\n",
    "Number of atoms = 4;  <br>\n",
    "Lattice constant (Angstoms) = 4.05;  <br>\n",
    "Cohesive energy (eV) = -3.359999988;  <br>\n",
    "All done! <br>\n",
    "</div>\n",
    "\n",
    "If you want to view the entire file (opening `log.lammps` in Notepad), then:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "!start notepad log.lammps"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "## LAMMPS Input Script Explained\n",
    "\n",
    "In this section, we will break down what LAMMPS is doing for each step. The easy way to do this on your own is to consult the LAMMPS manual for each command or go to the Internet LAMMPS manual, *i.e.*, at https://lammps.sandia.gov\n",
    "\n",
    "<br>\n",
    "<div class=\"alert alert-block alert-info\">\n",
    "    # Find minimum energy fcc configuration  <br>\n",
    "# Mark Tschopp </div>\n",
    "\n",
    "The `#` denotes a comment. Hence LAMMPS does not do anything for these lines. \n",
    "\n",
    "<br>\n",
    "<div class=\"alert alert-block alert-info\">\n",
    "# ---------- Initialize Simulation ---------------------  <br>\n",
    "clear  <br>\n",
    "units metal  <br>\n",
    "dimension 3  <br>\n",
    "boundary p p p  <br>\n",
    "atom_style atomic  <br>\n",
    "atom_modify map array <br>\n",
    "</div>\n",
    "\n",
    "This section initializes the simulations. The `clear` command clears all memory. The `units` command specifies the units that will be used for the remainder of the simulation; `metal` uses Angstroms and eV, among other units. The `dimension 3` command specifies a 3-dimensional simulation cell will be used (2-D is also an option). The `boundary p p p` specifies periodic boundaries in the x-, y-, and z-directions. \n",
    "\n",
    "<br>\n",
    "<div class=\"alert alert-block alert-info\">\n",
    "# ---------- Create Atoms ---------------------  <br>\n",
    "lattice \tfcc 4 <br>\n",
    "region\tbox block 0 1 0 1 0 1 units lattice <br>\n",
    "create_box\t1 box <br> <br>\n",
    "lattice\tfcc 4 orient x 1 0 0 orient y 0 1 0 orient z 0 0 1   <br>\n",
    "create_atoms 1 box <br>\n",
    "replicate 1 1 1 <br></div>\n",
    "\n",
    "The `lattice` command specifies what type of lattice is used (fcc, bcc, hcp, etc.) and the number following this specifies the lattice constant. The `region` command specifies the simulation cell. Here, we have used lattice units and specified that the simulation cell box is to be 1 lattice unit in each direction. The `create_box` command following this will use the parameters outlined in the `region` command to actually create the box. The `replicate` command can be used to replicate the periodic cell in each direction. \n",
    "\n",
    "<br>\n",
    "<div class=\"alert alert-block alert-info\">\n",
    "# ---------- Define Interatomic Potential --------------------- <br>\n",
    "pair_style eam/alloy  <br>\n",
    "pair_coeff * * Al99.eam.alloy Al <br>\n",
    "neighbor 2.0 bin  <br>\n",
    "neigh_modify delay 10 check yes  <br>\n",
    "</div>\n",
    "\n",
    "The `pair_style` command specifies what kind of interatomic potential will be used, while the `pair_coeff` specifies the file that the pair potential coefficients are stored in. The file extension for the interatomic potential file can sometimes give a clue as to which format is being used (eam.alloy = eam/alloy).\n",
    "\n",
    "<br>\n",
    "<div class=\"alert alert-block alert-info\">\n",
    "# ---------- Define Settings --------------------- <br>\n",
    "compute eng all pe/atom <br>\n",
    "compute eatoms all reduce sum c_eng <br>\n",
    "</div>\n",
    "\n",
    "Here, two computes are defined. In the first `compute` command, a variable named `eng` is defined to store the potential energy for each atom. In the second `compute` command, a variable named `eatoms` is defined to store the sum of all `eng` values. This is just to show how to use computes with user-defined variables.  Notice that the `pe` energy column during minimization is equivalent to the `c_eatoms` column, as expected.\n",
    "\n",
    "<br>\n",
    "<div class=\"alert alert-block alert-info\">\n",
    "# ---------- Run Minimization --------------------- <br> \n",
    "reset_timestep 0  <br>\n",
    "fix 1 all box/relax iso 0.0 vmax 0.001 <br>\n",
    "thermo 10  <br>\n",
    "thermo_style custom step pe lx ly lz press c_eatoms  <br>\n",
    "min_style cg  <br>\n",
    "minimize 1e-25 1e-25 5000 10000   <br>\n",
    "</div>\n",
    "\n",
    "The `reset_timestep` does just that. The `fix` command uses the `box/relax` setting, whereby all directions (`iso`) are relaxed to 0.0 Pa pressure for all atoms (`all`). The `thermo` specifies the output during minimization. The `thermo_style` specifies what type of output is shown to screen. Here I have used a `custom` list of metrics, including the time`step`, the potential energy (`pe`), the length of the box in x, y, and z (`lx`, `ly`, `lz`, respectively), the `press`ure, and the computed variable `eatoms`. The `min_style` specifies that conjugate gradient will be used for minimization and the `minimize` starts the minimization, *i.e.*, the simulation cell boundaries are relaxed from the specified lattice constant (4 Angstroms) to the actual lattice constant (4.05 Angstroms). \n",
    "\n",
    "<br>\n",
    "<div class=\"alert alert-block alert-info\">\n",
    "variable natoms equal \"count(all)\" <br>\n",
    "variable teng equal \"c_eatoms\" <br>\n",
    "variable length equal \"lx\" <br>\n",
    "variable ecoh equal \"v_teng/v_natoms\" \n",
    "</div>\n",
    "\n",
    "This section defines some variables, such as `natoms` for the number of atoms, `teng` for the total potential energy, `length` for the length of the simulation cell, and `ecoh` for the cohesive energy of Al.\n",
    "\n",
    "<br>\n",
    "<div class=\"alert alert-block alert-info\">\n",
    "print \"Total energy (eV) = \\${teng};\" <br>\n",
    "print \"Number of atoms = \\${natoms};\" <br>\n",
    "print \"Lattice constant (Angstoms) = \\${length};\" <br>\n",
    "print \"Cohesive energy (eV) = \\${ecoh};\" <br>\n",
    "print \"All done!\"\n",
    "</div>\n",
    "\n",
    "This section prints these values to screen and to the logfile. The `${}` is used to insert the variables defined earlier. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "## FAQs \n",
    "\n",
    "<br>\n",
    "<div class=\"alert alert-danger\">\n",
    "<strong>Question 1</strong>: But I wanted a simulation cell with <110> directions.  How would I change this?\n",
    "</div>\n",
    "\n",
    "Aha!  Yes, it is relatively easy to start changing the directions in the x, y, and z directions.  For instance, if you change this line: <br>\n",
    "`lattice fcc 4 orient x 1 0 0 orient y 0 1 0 orient z 0 0 1`\n",
    "\n",
    "to this one: <br>\n",
    "`lattice fcc 4 orient x 1 1 0 orient y -1 1 0 orient z 0 0 1`\n",
    "\n",
    "then you get a simulation cell that is oriented in the $<110>$ directions in the x- and y- directions.  If you mess up on the math, i.e., try 110 and 110 for the x and y directions (without the '-1'), then LAMMPS will return: <br>\n",
    "`ERROR: Lattice orient vectors are not orthogonal`\n",
    "\n",
    "So, if you try the $<110>$-oriented single crystal cell, LAMMPS automatically scales the x- and y-direction periodic lengths to 5.6568542 Angstroms (i.e., $4\\sqrt{2}$).  After minimization, the cohesive energy per atom is `-3.35999998818379` ev, th\n",
    "    \n",
    "<br>\n",
    "<div class=\"alert alert-danger\">\n",
    "<strong>Question 2</strong>: I typed in the above line and nothing happened.\n",
    "</div>\n",
    "\n",
    "Make sure that you are in the same directory as the LAMMPS executable. Make sure that you are typing in the correct filename. \n",
    "\n",
    "<br>\n",
    "<div class=\"alert alert-danger\">\n",
    "<strong>Question 3</strong>: I keep getting an error with the potential, i.e., potential file not found.\n",
    "</div>\n",
    "\n",
    "First, check that the potential file is in the directory that you are running out of. Although, you can insert paths, if you want to store the potentials in another directory. Second, make sure that the potential file name is the same as that given in the input script. For instance, Windows has the habit of saving text files (like the potential files) with .txt extensions. If you happen to be running from a Windows operating system, I would change the settings so that you can see the extensions of the files as well. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "## Tutorial Links\n",
    "\n",
    "[Click here to open the next tutorial](LAMMPS-Tutorials-02.ipynb)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
